import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const UserNameKey = 'username'
const UserIdKey = 'userId'
const RoleKey = 'role'

// Token相关操作
export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

// 用户名相关操作
export function getUsername() {
  return Cookies.get(UserNameKey)
}

export function setUsername(username) {
  return Cookies.set(UserNameKey, username)
}

export function removeUsername() {
  return Cookies.remove(UserNameKey)
}

// 用户ID相关操作
export function getUserId() {
  return Cookies.get(UserIdKey)
}

export function setUserId(userId) {
  return Cookies.set(UserIdKey, userId)
}

export function removeUserId() {
  return Cookies.remove(UserIdKey)
}

// 用户角色相关操作
export function getRole() {
  return Cookies.get(RoleKey)
}

export function setRole(role) {
  return Cookies.set(RoleKey, role)
}

export function removeRole() {
  return Cookies.remove(RoleKey)
}

// 获取完整用户信息
export function getUserInfo() {
  return {
    username: getUsername(),
    userId: getUserId(),
    role: getRole(),
    token: getToken()
  }
}

// 移除所有用户相关Cookie
export function removeAllUserCookies() {
  removeToken()
  removeUsername()
  removeUserId()
  removeRole()
}

// 获取任意Cookie
export function getCookie(name) {
  return Cookies.get(name)
}

// 设置任意Cookie
export function setCookie(name, value, options = {}) {
  return Cookies.set(name, value, options)
}

// 移除任意Cookie
export function removeCookie(name) {
  return Cookies.remove(name)
}